const path = require('path')
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    mode:"none",
    devtool: 'eval-source-map',
    resolve:{
      extensions: ['.js','.ts']
    },
    devServer: {
        host: 'localhost',
        port: 8080,
    },
    entry:'./src/index.ts',
    output:{
        path: path.resolve(__dirname, '../dist'),   // 打包文件的输出目录
        filename:'js/[name].js',
        chunkFilename: 'js/[name].js',
        publicPath: '', // 本地
    },
    module: {
        rules: [
          {
            test: /\.(tsx|ts)?$/,
            loader: 'ts-loader',
            exclude: /node_modules/,
          },      {
            test: /\.css$/,
            use: [
              "style-loader",
              "css-loader"
            ]
          },
          {
            // js文件使用babel-loader来处理
            test: /\.?js$/,
            exclude: /(node_modules)/,
            use: {
              loader: 'babel-loader',
            }
          },
        ],
    },
    plugins: [
        // 启用模块热替换(HMR)
        new webpack.HotModuleReplacementPlugin(),
          // plugins里初始化插件
        new HtmlWebpackPlugin({ 
            template: './public/index.html' ,
            filename: 'index.html' ,
            title: 'Webpack Test Title',
            currentVersion: Math.random()
            // inject: true
        })
    ]
}